package SlidingWindow;

import java.util.Random;

/**
 * @ClassName LC1004
 * @Description TODO
 * @Author ZJX
 * @Date 2024/9/20 9:55
 * @Version 1.0
 */
public class LC1004 {
    public int longestOnes(int[] nums, int k) {
        int ret = 0; // 初始化最大长度

        if(k >= nums.length){
            return nums.length;
        }
        for(int left = 0, right = 0, zero = 0; right < nums.length; right++){
            if (nums[right] == 0){
                zero++;
            }

            while (zero > k){
                if (nums[left++] == 0){
                    zero--;
                }
            }
            ret = Math.max(ret,right - left + 1);
        }
        return ret;
    }
}
